Skip to main content

控制单轴的运动

PLCopenSingle.project 安装目录下的示例项目 CODESYS 在下面 ..\CODESYS SoftMotion\Examples.

此示例演示如何通过 PLCopen 标准化功能块控制驱动器。

  1. 插入一个名为的虚拟驱动器 Drive 在下面的设备树中 SoftMotion 通用轴池.

  2. 创建一个 MOTION_PRG ST中的程序。

    PROGRAM MOTION_PRG
    VAR
            iStatus: INT;
            Power: MC_Power;
            MoveAbsolute: MC_MoveAbsolute;
            p:REAL:=100;
    END_VAR
    
    CASE iStatus OF
    
    // initialization of the axis
    0:
            Power(Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE, Axis:=Drive);
            IF Power.Status THEN
                    iStatus := iStatus + 1;
            END_IF
    
    // Move the axis to position p by use of the MC_MoveAbsolute function block
    1:
            MoveAbsolute(Execute:=TRUE, Position:= p, Velocity:=100, Acceleration:=100, Deceleration:=100, Axis:=Drive);
            IF MoveAbsolute.Done THEN
                    MoveAbsolute(Execute:=FALSE, Axis:=Drive);
                    iStatus := iStatus + 1;
            END_IF
    
    // Move the axis back to position 0 by use of the MC_MoveAbsolute function block:
    2:
            MoveAbsolute(Execute:=TRUE, Position:= 0, Velocity:=100, Acceleration:=100, Deceleration:=100, Axis:=Drive);
            IF MoveAbsolute.Done THEN
                    MoveAbsolute(Execute:=FALSE, Axis:=Drive);
                    iStatus := 1;
            END_IF
  3. 将 MOTION_PRG 程序的调用添加到任务中 主要任务.

    设备树:

    _sm_img_example_single_axis_2.png
  4. 将项目下载到控制器并启动它。

  5. 打开 驾驶 编辑器中的虚拟轴。

    在里面 在线的 的一部分 一般的 选项卡,您会看到轴运动。

    _sm_img_example_single_axis_1.png